Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app): app.runWithContext() #7451

Merged
merged 3 commits into from
Apr 5, 2023
Merged

feat(app): app.runWithContext() #7451

merged 3 commits into from
Apr 5, 2023

Conversation

posva
Copy link
Member

@posva posva commented Jan 2, 2023

Allows accessing globals provided at the app level with app.provide() via a regular inject() call as long as you have access to the application. Useful for Pinia, vue-router, Nuxt, Quasar, VueUse, and other advanced use cases.

I named the function runWithContext() to look like effect.run() but maybe it should be named something different like runWithProvides() since it only ensures inject() behavior but I think keeping a more generic names allows to add other things if the future like onServerPrefetch() and so.

@posva posva added the ✨ feature request New feature or request label Jan 2, 2023
@posva
Copy link
Member Author

posva commented Feb 23, 2023

I also think it's worth giving functions like the callback passed to router.beforeEach() and the setup function in pinia a name that can be found in docs. Something like inject-aware function/context. That way, we could have a page in documentation explaining the concept and library authors could mention this as inject-aware (or whatever other name that makes sense) to indicate that inject() and provide() can safely be used in a context and add an external link to that page. It could maybe create more awareness of the need to call composables within an inject-aware functions like setup().

@antfu antfu mentioned this pull request Mar 13, 2023
4 tasks
Copy link
Member

@antfu antfu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would also be greatly helpful for Nuxt and VueUse as well 👍

posva and others added 3 commits April 5, 2023 14:57
Allows accessing globals provided at the app level with `app.provide()`
via a regular `inject()` call as long as you have access to the
application. Useful for Pinia, vue-router, Nuxt, Quasar, and other
advanced use cases.

- vuejs/pinia#1784
@yyx990803 yyx990803 merged commit 869f3fb into main Apr 5, 2023
@yyx990803 yyx990803 deleted the feat/run-app-context branch April 5, 2023 07:18
IAmSSH pushed a commit to IAmSSH/core that referenced this pull request May 14, 2023
posva added a commit to posva/tanstack-query-fork that referenced this pull request Aug 18, 2023
This feature requires Vue 3.3.0, which has been out for a while now. It
allows using vue-query APIs in places where it is valid to use them but
currently throws an error.

- `hasInjectionContext()`: vuejs/core#8111
- `app.runWithContext()`: vuejs/core#7451
DamianOsipiuk pushed a commit to posva/tanstack-query-fork that referenced this pull request Aug 25, 2023
This feature requires Vue 3.3.0, which has been out for a while now. It
allows using vue-query APIs in places where it is valid to use them but
currently throws an error.

- `hasInjectionContext()`: vuejs/core#8111
- `app.runWithContext()`: vuejs/core#7451
DamianOsipiuk pushed a commit to posva/tanstack-query-fork that referenced this pull request Aug 25, 2023
This feature requires Vue 3.3.0, which has been out for a while now. It
allows using vue-query APIs in places where it is valid to use them but
currently throws an error.

- `hasInjectionContext()`: vuejs/core#8111
- `app.runWithContext()`: vuejs/core#7451
DamianOsipiuk added a commit to TanStack/query that referenced this pull request Aug 30, 2023
* feat(vue-query): support injectable contexts

This feature requires Vue 3.3.0, which has been out for a while now. It
allows using vue-query APIs in places where it is valid to use them but
currently throws an error.

- `hasInjectionContext()`: vuejs/core#8111
- `app.runWithContext()`: vuejs/core#7451

* refactor: add dev warning for effectScope

* fix: add memory leak warnings, fix tests

* chore: bump vue-demi

* chore: bump vue version in integrations

---------

Co-authored-by: Damian Osipiuk <osipiukd+git@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ feature request New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants